﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PMS.XCMG.Util;

namespace PMS.XCMG.Entity
{
    /// <summary>
    /// 故障状态
    /// </summary>
    public enum FaultStatus
    {
        /// <summary>
        /// 正在发生
        /// </summary>
        Happening = 0,
        /// <summary>
        /// 已排除解决
        /// </summary>
        Resolved = 1,
        /// <summary>
        /// 挂起（暂不做处理）
        /// </summary>
        Suspend = 2,
    }

    /// <summary>
    /// 设备故障报警
    /// </summary>
    public partial class DeviceFault : BusEntity
    {
        /// <summary>
        /// 设备编码（Equipment.Code）
        /// </summary>
        public string EquipmentCode { set; get; }
        /// <summary>
        /// 故障报警编码(FaultType.Code)
        /// </summary>
        public string Code { get; set; }
        /// <summary>
        /// 故障报警名称
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 故障报警状态
        /// </summary>
        public FaultStatus Status { set; get; }
        /// <summary>
        /// 故障报警发生时间
        /// </summary>
        public DateTime FaultTime { set; get; }
        /// <summary>
        /// 故障解决时间
        /// </summary>
        public DateTime? SolutionTime { set; get; }        
    }

    public partial class DeviceFault : BusEntity
    {
    }

    /// <summary>
    /// 实体配置
    /// OnModelCreating
    /// </summary>
    public class DeviceFaultTypeConfig : BusEntityTypeConfig<DeviceFault>, IEntityTypeConfiguration<DeviceFault>
    {
        public override void Configure(EntityTypeBuilder<DeviceFault> builder)
        {
            base.Configure(builder);

            #region 主外键关系
            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.EquipmentCode).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Code).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Name).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Status).IsRequired();
            builder.Property(p => p.FaultTime);
            builder.Property(p => p.SolutionTime);
            #endregion

            #region 备注
            builder.HasComment("设备故障报警");
            builder.Property(p => p.EquipmentCode).HasComment("设备编码（Equipment.Code）");
            builder.Property(p => p.Code).HasComment("故障编码");
            builder.Property(p => p.Name).HasComment("故障名称");
            builder.Property(p => p.Status).HasComment("故障状态");
            builder.Property(p => p.FaultTime).HasComment("故障时间");
            builder.Property(p => p.SolutionTime).HasComment("解决时间");
            #endregion

            #region 种子数据
            #endregion
        }
    }
}
